<script setup lang="ts">
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { PureTableBar } from "@/components/RePureTableBar";
import Refresh from "@iconify-icons/ep/refresh";
import { ref } from "vue";
import { useExrule } from "./utils/hook";
defineOptions({
  name: "GoodsTransfer"
});

const formRef = ref();

const {
  form,
  columns,
  childColumns,
  loading,
  dataList,
  pagination,
  onSearch,
  handleSizeChange,
  handleCurrentChange,
  resetForm,
  openDialog,
  handleDelete
} = useExrule();
</script>

<template>
  <div class="main">
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px] overflow-auto"
    >
      <el-form-item label="调账编码：" prop="reconciliationNumber">
        <el-input
          v-model.trim="form.reconciliationNumber"
          placeholder="请输入"
          clearable
          class="!w-[180px]"
        />
      </el-form-item>
      <el-form-item label="库存调账流程编号：" prop="processNumber">
        <el-input
          v-model.trim="form.processNumber"
          placeholder="请输入"
          clearable
          class="!w-[180px]"
        />
      </el-form-item>
      <el-form-item label="门店名称：" prop="storeName">
        <el-input
          v-model.trim="form.storeName"
          placeholder="请输入"
          clearable
          class="!w-[180px]"
        />
      </el-form-item>
      <el-form-item label="业务日期：" prop="businessDate">
        <el-date-picker
          v-model="form.businessDate"
          class="!w-[250px]"
          type="daterange"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="YYYYMMDD"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ri:search-line')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <PureTableBar
      class="w-full"
      style="transition: width 220ms cubic-bezier(0.4, 0, 0.2, 1)"
      title=""
      :columns="columns"
      @refresh="onSearch"
    >
      <template #buttons>
        <el-button type="primary" @click="openDialog()">新增</el-button>
      </template>
      <template v-slot="{ size, dynamicColumns }">
        <pure-table
          ref="tableRef"
          align-whole="center"
          showOverflowTooltip
          table-layout="auto"
          :loading="loading"
          :size="size"
          adaptive
          :adaptiveConfig="{ offsetBottom: 90 }"
          :data="dataList"
          :columns="dynamicColumns"
          :pagination="pagination"
          :paginationSmall="size === 'small' ? true : false"
          :header-cell-style="{
            background: 'var(--el-fill-color-light)',
            color: 'var(--el-text-color-primary)'
          }"
          @page-size-change="handleSizeChange"
          @page-current-change="handleCurrentChange"
        >
          <template #operation="{ row }">
            <el-popconfirm
              :title="`是否确认删除?`"
              @confirm="handleDelete(row)"
            >
              <template #reference>
                <el-button class="!ml-1" link type="danger">删除</el-button>
              </template>
            </el-popconfirm>
          </template>
          <!-- 子表格 -->
          <template #expand="{ row }">
            <div class="ml-[100px]">
              <pure-table
                row-key="id"
                align-whole="center"
                :data="row.transferGoodsDetailResponses"
                :columns="childColumns"
                :header-cell-style="{
                  background: 'var(--el-fill-color-light)',
                  color: 'var(--el-text-color-primary)'
                }"
              />
            </div>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<style lang="scss" scoped></style>
